package offer;

import java.util.HashMap;

public class Offer35 {

    class Solution {
        private HashMap<Node, Node> map = new HashMap<Node, Node>();

        public Node copyRandomList(Node head) {
            if (head == null) {
                return null;
            }

            if (!map.containsKey(head)) {
                Node newNode = new Node(head.val);
                map.put(head, newNode);
                newNode.next = copyRandomList(head.next);
                newNode.random = copyRandomList(head.random);
            }

            return map.get(head);
        }
    }
}
